using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Pacoca
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        Textura classTextura;
        public static Vector2 tamanhoTela;
        Background classBackground;
        Player classPlayer;
        public static Color corFundo;
        public static GameTime gameTime2;

        Vector2 tileSize = new Vector2(50, 50); //Tamanho de cada tileset.
        TileMap tileMap;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }
        protected override void Initialize()
        {
            graphics.PreferredBackBufferWidth = 800;
            graphics.PreferredBackBufferHeight = 600;
            graphics.ApplyChanges();
            base.Initialize();
            tamanhoTela = new Vector2(Window.ClientBounds.Width, Window.ClientBounds.Height);
            classBackground = new Background();
            classPlayer = new Player();
        }
        protected override void LoadContent()
        {

            spriteBatch = new SpriteBatch(GraphicsDevice);
            classTextura = new Textura(Content);
            tileMap = new TileMap(Content, tileSize);

        }

        protected override void UnloadContent()
        {

        }

        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            gameTime2 = gameTime;
            classBackground.Update(gameTime);
            classPlayer.Update(gameTime);
            tileMap.Update(gameTime, Window.ClientBounds);

            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(corFundo);
            spriteBatch.Begin();
            classBackground.Draw(gameTime, spriteBatch);
            classPlayer.Draw(gameTime, spriteBatch);
            spriteBatch.End();
            tileMap.Draw(gameTime, spriteBatch);
            base.Draw(gameTime);
        }
    }
}
